/**
 * 
 */
package com.lb.myeam.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jspsmart.upload.SmartUpload;

/**
 * @author 01053495-pc
 *
 */
public class ServletUpload extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	private ServletConfig config;
	
	final public void init(ServletConfig config) throws ServletException {
		this.config = config;
	}


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		out.println("<HTML>");
		out.println("<BODY BGCOLOR='white'>");
		out.println("<H1>jspSmartUpload : Servlet Sample</H1>");
		out.println("<HR>");
		
		// 变量定义
		int count = 0;
		SmartUpload mySmartUpload = new SmartUpload();
		try {
		//Smart上传三句核心代码
		mySmartUpload.initialize(config, request, response);
		mySmartUpload.upload();
		count = mySmartUpload.save("/upload");

		out.println(count + " file uploaded.");
		} catch (Exception e) {
		out.println("Unable to upload the file.<br>");
		out.println("Error : " + e.toString());
		}
		out.println("</BODY>");
		out.println("</HTML>");
	}

}
